package com.cicc.beergamevirtualsimulationsystem.service.recordInit;

import com.cicc.beergamevirtualsimulationsystem.entity.RecordDetailEntity;
import com.cicc.beergamevirtualsimulationsystem.entity.RecordEntity;
import com.cicc.beergamevirtualsimulationsystem.entity.RoleBindingEntity;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Configuration
public class RecordInitHolder {
    private static Map<Integer, Integer> paramMap;

    private static Map<String, RecordEntity> recordEntityMapOne;

    private static Map<String, RecordEntity> recordEntityMapN;

    private static Map<String, RecordDetailEntity> recordDetailEntityMapOne;

    private static Map<String, RecordDetailEntity> recordDetailEntityMapN;
    private static Map<String, RoleBindingEntity> roleBindingEntityMap;

    private static Integer deliveryCycle;
    private static String roomId;
    private static Integer period;

    public static final Map<Integer, BaseRecordInit> recordInitMap = new HashMap<>();

    public RecordInitHolder(List<BaseRecordInit> baseRecordInits){
        for (BaseRecordInit baseRecordInit : baseRecordInits) {
            recordInitMap.put(baseRecordInit.getType(), baseRecordInit);
        }
    }

    public BaseRecordInit getRecordInit(Integer initType){
        BaseRecordInit baseRecordInit = recordInitMap.get(initType);
        baseRecordInit.setParamMap(paramMap);
        baseRecordInit.setRecordEntityMapOne(recordEntityMapOne);
        baseRecordInit.setRecordEntityMapN(recordEntityMapN);
        baseRecordInit.setRecordDetailEntityMapOne(recordDetailEntityMapOne);
        baseRecordInit.setRecordDetailEntityMapN(recordDetailEntityMapN);
        baseRecordInit.setRoleBindingEntityMap(roleBindingEntityMap);
        baseRecordInit.setDeliveryCycle(deliveryCycle);
        baseRecordInit.setPeriod(period);
        baseRecordInit.setRoomId(roomId);
        return baseRecordInit;
    }

    public void init(String roomId, Integer period, Integer deliveryCycle, Map<Integer, Integer> paramMap,
                     Map<String, RecordEntity> recordEntityMapOne, Map<String, RecordEntity>recordEntityMapN,
                     Map<String, RecordDetailEntity> recordDetailEntityMapOne, Map<String, RecordDetailEntity> recordDetailEntityMapN,
                     Map<String, RoleBindingEntity> roleBindingEntityMap){
        RecordInitHolder.roomId = roomId;
        RecordInitHolder.period = period;
        RecordInitHolder.deliveryCycle = deliveryCycle;
        RecordInitHolder.paramMap = paramMap;
        RecordInitHolder.recordEntityMapN = recordEntityMapN;
        RecordInitHolder.recordEntityMapOne = recordEntityMapOne;
        RecordInitHolder.recordDetailEntityMapOne = recordDetailEntityMapOne;
        RecordInitHolder.recordDetailEntityMapN = recordDetailEntityMapN;
        RecordInitHolder.roleBindingEntityMap = roleBindingEntityMap;
    }
}
